package com.aiyige.page.webview.model;

import android.text.TextUtils;

public class PreloadTask {
    public static final int TYPE_INFO = 1;
    public static final int TYPE_MAJOR_COURSE = 2;
    public static final int TYPE_UNKNOWN = 4;
    public static final int TYPE_SHUTDOWN = 3;
    int type;
    String url;

    public PreloadTask() {
    }

    private PreloadTask(Builder builder) {
        setType(builder.type);
        setUrl(builder.url);
    }

    public static Builder newBuilder() {
        return new Builder();
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public static final class Builder {
        private int type;
        private String url;

        private Builder() {
            type = TYPE_SHUTDOWN;
            url = "";
        }

        public Builder type(int val) {
            type = val;
            return this;
        }

        public Builder url(String val) {
            url = val;
            return this;
        }

        public PreloadTask build() {
            return new PreloadTask(this);
        }
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }

        if (this == obj) {
            return true;
        }

        if (!(obj instanceof PreloadTask)) {
            return false;
        }

        PreloadTask other = (PreloadTask) obj;
        if (other.getType() != this.getType()) {
            return false;
        }
//        if (!TextUtils.isEmpty(other.getUrl()) && !TextUtils.isEmpty(getUrl())) {
//            if (!other.getUrl().equals(getUrl())) {
//                return false;
//            }
//        } else if (!TextUtils.isEmpty(other.getUrl()) || !TextUtils.isEmpty(getUrl())) {
//            return false;
//        }
        return true;
    }
}
